<?php
/**
 * Created by Silent Night.
 * Author: Silent Night
 * email: silentwolf_wp@163.com
 * Date: 2017/9/28
 * Time: 9:19
 */

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Session;

class My extends Controller
{
    private $_model;
    private $title_field = [

    ];
    public $pagesize = 10;

    public function _initialize()
    {


        $this->_model = new \app\admin\model\Devlist();
        $this->assign('LoginUserInfo', $this->LoginUserInfo);


        //获取当前用户的权限信息
        $this->assign('ruleLists', $this->LoginUserInfo['CurrPower']);
    }

    /**
     * 列表页
     * @return mixed
     */
    public function index()
    {

        return $this->fetch('index');
    }

    public function clearAlert()
    {
        $num = 0;
        if (in_array($this->LoginUserInfo['UserInfo']['group'], array(100, 101, 102))) {
            $alertModel = new \app\admin\model\Alert();
            $ty = 0;
            if ($this->LoginUserInfo['UserInfo']['group'] == 100) {
                $ty = 1;
            } else if ($this->LoginUserInfo['UserInfo']['group'] == 101) {
                $ty = 2;
            } else if ($this->LoginUserInfo['UserInfo']['group'] == 102) {
                $ty = 3;
            }
            clearAlert($ty);

        }
        $return = ['err' => 0, 'msg' => '有任务'];
        return json($return);

    }

    public function msgAlt()
    {
        $num = 0;
        if (in_array($this->LoginUserInfo['UserInfo']['group'], array(100, 101, 102))) {
            $alertModel = new \app\admin\model\Alert();
            $ty = 0;
            if ($this->LoginUserInfo['UserInfo']['group'] == 100) {
                $ty = 1;
            } else if ($this->LoginUserInfo['UserInfo']['group'] == 101) {
                $ty = 2;
            } else if ($this->LoginUserInfo['UserInfo']['group'] == 102) {
                $ty = 3;
            }
            $alertData = $alertModel->getDataForWhere(array('ty' => $ty));
            if (!empty($alertData)) {
                if ($alertData['num'] > 0) {
                    $num = $alertData['num'];
                }
            }

        }
        $return = ['err' => 0, 'msg' => '有任务', 'count' => $num];
        return json($return);

    }

    public function selectMyOrdep()
    {
        $ty = trim(input("request.ty"));//auth
        $userModel = new \app\admin\model\User();
        if ($ty == 1)//查询我的
        {
            $where['uid'] = $this->LoginUserInfo['UserInfo']['id'];

            $lists = $this->_model->lists($where, 10000);

        } else if ($ty == 2)//部门的
        {


            //查询我的部门的人员start
            $myFirstDep = $this->LoginUserInfo['FirstDep'];
            $mySecondDep = $this->LoginUserInfo['SecondDep'];
            $filterUid = array();
            if ($mySecondDep) {
                $tempUID = $userModel->getDataForWheres(array(
                    'depid' => $mySecondDep['id']
                ), "id");
                foreach ($tempUID as $key => $val) {
                    $filterUid[] = $val['id'];
                }
            } else if ($myFirstDep) {
                $tempUID = $userModel->getDataForWheres(array(
                    'first_depid' => $myFirstDep['id']
                ), "id");
                foreach ($tempUID as $key => $val) {
                    $filterUid[] = $val['id'];
                }
            }

            //查询我的部门的人员end

            $where['uid'] = array('in', $filterUid);

        }

        $lists = $this->_model->lists($where, 10000);

        if (!empty($lists['data'])) {

            $userList = array();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['useUser'] = array();


                if ($val['uid']) {
                    if ($userList[$val['uid']]) {
                        $lists['data'][$key]['dvename'] = $userList[$val['uid']]['nickname'] . "的" . $lists['data'][$key]['dvename'];
                    } else {
                        $tmpUserInfo = $userModel->getID($val['uid']);
                        if ($tmpUserInfo) {
                            $userList[$val['uid']] = $tmpUserInfo;
                            $lists['data'][$key]['dvename'] = $tmpUserInfo['nickname'] . "的" . $userList[$val['uid']]['nickname'] . "的" . $lists['data'][$key]['dvename'];;
                        }
                    }
                }
            }
        }
        $tmplist = array();
        if ($lists['total'] > 0) {
            $tmplist = $lists['data'];
        }
        $rlist = array(
            'err' => 0,
            'data' => $tmplist
        );
        return json($rlist);

    }

    public function zclists()
    {

        $userModel = new \app\admin\model\User();
        $ser_key = trim(input("request.ser_key"));//auth
        $ser_val = trim(input("request.ser_val"));//auth
        $firstType = trim(input("request.firstType"));//auth
        $secondType = trim(input("request.secondType"));//auth
        $stat = trim(input("request.stat"));//auth
        $starttime = trim(input("request.starttime"));//auth
        $endtime = trim(input("request.endtime"));//auth
        $is_show = trim(input("request.is_show"));//auth

        if ($is_show == '') {
            $is_show = 1;
        }

        if ($ser_key && $ser_val) {

            $where[$ser_key] = array('like', '%' . $ser_val . '%');

        }

        if ($firstType >= '0') {
            $where['first_type'] = $firstType;
        }
        if ($secondType >= '0') {
            $where['type'] = $secondType;
        }

        if ($stat >= '0') {
            $where['stat'] = $stat;
        } else {
            if ($is_show == 1) {
                $where['stat'] = array('neq', 3);
            }
        }

        if (!empty($starttime) && !empty($endtime)) {
            $starttime = $starttime . " 00:00:00";
            $endtime = $endtime . " 23:59:59";
            $where['stime'] = array('between', $starttime . "," . $endtime);
        }
        $where['uid'] = $this->LoginUserInfo['UserInfo']['id'];

        $lists = $this->_model->lists($where, $this->pagesize);

        if (!empty($lists['data'])) {

            $userList = array();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['rkUser'] = array();
                $lists['data'][$key]['useUser'] = array();
                if ($val['suid']) {
                    if ($userList[$val['suid']]) {
                        $lists['data'][$key]['rkUser'] = $userList[$val['suid']];
                    } else {
                        $tmpUserInfo = $userModel->getID($val['suid']);
                        if ($tmpUserInfo) {
                            $userList[$val['suid']] = $tmpUserInfo;
                            $lists['data'][$key]['rkUser'] = $tmpUserInfo;
                        }
                    }
                }


                if ($val['uid']) {
                    if ($userList[$val['uid']]) {
                        $lists['data'][$key]['useUser'] = $userList[$val['uid']];
                    } else {
                        $tmpUserInfo = $userModel->getID($val['uid']);
                        if ($tmpUserInfo) {
                            $userList[$val['uid']] = $tmpUserInfo;
                            $lists['data'][$key]['useUser'] = $tmpUserInfo;
                        }
                    }
                }
            }
        }
        $this->assign('lists', $lists);


        //查询资产分类


        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $firstID = $FirstDepList[0]['id'];
        if ($firstType) {
            $firstID = $firstType;
        }
        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $firstID
        ));//查询二级部门

        $SecondDepListTmp = array();
        foreach ($SecondDepList as $k => $v) {
            $SecondDepListTmp[$v['id']] = $v;
        }
        $SecondDepList = $SecondDepListTmp;


        $FirstDepListTmp = array();
        foreach ($FirstDepList as $k => $v) {
            $FirstDepListTmp[$v['id']] = $v;
        }
        $FirstDepList = $FirstDepListTmp;


        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $FirstDepList);


        //查询学生的部门信息start
        //查询用户部门
        $depModel = new \app\admin\model\Dep();

        $tmpUserDepList = $depModel->getAll();//查询一级部门

        $userDepList = array();
        if ($tmpUserDepList) {
            foreach ($tmpUserDepList as $key => $val) {
                $userDepList[$val['id']] = $val;
            }
        }
        $this->assign('userDepList', $userDepList);
        //查询学生的部门信息end


        $this->assign('request', input("request."));
        return view('zclists');

    }


    public function bmlists()
    {

        $userModel = new \app\admin\model\User();
        //查询我的部门的人员start
        $myFirstDep = $this->LoginUserInfo['FirstDep'];
        $mySecondDep = $this->LoginUserInfo['SecondDep'];
        $filterUid = array();
        if ($mySecondDep) {
            $tempUID = $userModel->getDataForWheres(array(
                'depid' => $mySecondDep['id']
            ), "id");
            foreach ($tempUID as $key => $val) {
                $filterUid[] = $val['id'];
            }
        } else if ($myFirstDep) {
            $tempUID = $userModel->getDataForWheres(array(
                'first_depid' => $myFirstDep['id']
            ), "id");
            foreach ($tempUID as $key => $val) {
                $filterUid[] = $val['id'];
            }
        }

        //查询我的部门的人员end

        $ser_key = trim(input("request.ser_key"));//auth
        $ser_val = trim(input("request.ser_val"));//auth
        $firstType = trim(input("request.firstType"));//auth
        $secondType = trim(input("request.secondType"));//auth
        $stat = trim(input("request.stat"));//auth
        $starttime = trim(input("request.starttime"));//auth
        $endtime = trim(input("request.endtime"));//auth
        $is_show = trim(input("request.is_show"));//auth

        if ($is_show == '') {
            $is_show = 1;
        }

        if ($ser_key && $ser_val) {
            if ($ser_key == "uid_name")//姓名
            {
                $tmpUserInfo = $userModel->getDataForWhere(array(
                    'nickname' => $ser_val
                ));
                if (empty($tmpUserInfo)) {

                    $filterUid = array();
                } else {

                    if (in_array($tmpUserInfo['id'], $filterUid)) {
                        $filterUid = array($tmpUserInfo['id']);
                    } else {
                        $filterUid = array();
                    }
                }
            } else if ($ser_key == "uid_name1")//账号
            {
                $tmpUserInfo = $userModel->getDataForWhere(array(
                    'uname' => $ser_val
                ));
                if (empty($tmpUserInfo)) {
                    $filterUid = array();
                } else {
                    if (in_array($tmpUserInfo['id'], $filterUid)) {
                        $filterUid = array($tmpUserInfo['id']);
                    } else {
                        $filterUid = array();
                    }
                }
            } else if ($ser_key == "uid") {
                if (in_array($ser_val, $filterUid)) {
                    $filterUid = array($ser_val);
                } else {
                    $filterUid = array();
                }
            } else {
                $where[$ser_key] = array('like', '%' . $ser_val . '%');
            }
        }

        if ($firstType >= '0') {
            $where['first_type'] = $firstType;
        }
        if ($secondType >= '0') {
            $where['type'] = $secondType;
        }

        if ($stat >= '0') {
            $where['stat'] = $stat;
        } else {
            if ($is_show == 1) {
                $where['stat'] = array('neq', 3);
            }
        }

        if (!empty($starttime) && !empty($endtime)) {
            $starttime = $starttime . " 00:00:00";
            $endtime = $endtime . " 23:59:59";
            $where['stime'] = array('between', $starttime . "," . $endtime);
        }
        $where['uid'] = array('in', $filterUid);


        $lists = $this->_model->lists($where, $this->pagesize);

        if (!empty($lists['data'])) {

            $userList = array();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['rkUser'] = array();
                $lists['data'][$key]['useUser'] = array();
                if ($val['suid']) {
                    if ($userList[$val['suid']]) {
                        $lists['data'][$key]['rkUser'] = $userList[$val['suid']];
                    } else {
                        $tmpUserInfo = $userModel->getID($val['suid']);
                        if ($tmpUserInfo) {
                            $userList[$val['suid']] = $tmpUserInfo;
                            $lists['data'][$key]['rkUser'] = $tmpUserInfo;
                        }
                    }
                }


                if ($val['uid']) {
                    if ($userList[$val['uid']]) {
                        $lists['data'][$key]['useUser'] = $userList[$val['uid']];
                    } else {
                        $tmpUserInfo = $userModel->getID($val['uid']);
                        if ($tmpUserInfo) {
                            $userList[$val['uid']] = $tmpUserInfo;
                            $lists['data'][$key]['useUser'] = $tmpUserInfo;
                        }
                    }
                }
            }
        }
        $this->assign('lists', $lists);


        //查询资产分类


        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $firstID = $FirstDepList[0]['id'];
        if ($firstType) {
            $firstID = $firstType;
        }
        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $firstID
        ));//查询二级部门

        $SecondDepListTmp = array();
        foreach ($SecondDepList as $k => $v) {
            $SecondDepListTmp[$v['id']] = $v;
        }
        $SecondDepList = $SecondDepListTmp;


        $FirstDepListTmp = array();
        foreach ($FirstDepList as $k => $v) {
            $FirstDepListTmp[$v['id']] = $v;
        }
        $FirstDepList = $FirstDepListTmp;


        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $FirstDepList);


        //查询学生的部门信息start
        //查询用户部门
        $depModel = new \app\admin\model\Dep();

        $tmpUserDepList = $depModel->getAll();//查询一级部门

        $userDepList = array();
        if ($tmpUserDepList) {
            foreach ($tmpUserDepList as $key => $val) {
                $userDepList[$val['id']] = $val;
            }
        }
        $this->assign('userDepList', $userDepList);
        //查询学生的部门信息end


        $this->assign('request', input("request."));
        return view('bmlists');

    }


    public function selectTypeChange()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $model = new \app\admin\model\Devtype();
        $res = $model->getDataForWheres(
            array('father' => $id)
        );


        $return = ['err' => 0, 'msg' => '操作成功', 'data' => $res];
        return json($return);


    }


    /**
     * 删除
     * 支持批量删除和单条删除
     * @return mixed
     */
    public function delData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $oldGroup = $this->_model->getDataForWhere(array(
            'id' => $id
        ));

        $res = $this->_model->delData(array('id' => $id));

        if ($res) {

            //操作日志记录
            $action = "资产编号[" . $oldGroup['dveid'] . "] 删除";

            $this->recordSystemLog([
                'user' => $this->LoginUserInfo['UserInfo']['id'],
                'time' => date("Y-m-d H:i:s"),
                'action' => $action,
                'type' => 1,
            ]);


            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }


    }


    public function recordSystemLog($arr)
    {
        $model = new \app\admin\model\Log();
        $model->add($arr);
    }

    /**
     * 删除
     * 支持批量删除和单条删除
     * @return mixed
     */
    public function del_depthlog()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $model = new \app\admin\model\Archives();
        $oldGroup = $model->getDataForWhere(array(
            'id' => $id
        ));

        $res = $model->delData(array('id' => $id));

        if ($res) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }


    }

    public function generaCode()
    {
        $id = trim(input("request.id"));//auth
        if (!empty($id)) {
            $devtypeMode = new \app\admin\model\Devtype();
            $devTypeData = $devtypeMode->getID($id);
            $dveid = autoGerCode($devTypeData['abb']);
            $return = ['err' => 0, 'msg' => '资产编号生成失败', 'data' => $dveid];
            return json($return);
        }

        $return = ['err' => 3, 'msg' => '资产编号生成失败'];
        return json($return);
    }


    public function addData()
    {
        $time = time();
        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {
            $type = trim(input("request.type"));//auth
            if (empty($type)) {
                $return = ['err' => 3, 'msg' => '请选择资产分类'];
                return json($return);
            }
            $dveid = trim(input("request.dveid"));//auth

            if (empty($dveid)) {
                $devtypeMode = new \app\admin\model\Devtype();
                $devTypeData = $devtypeMode->getID($type);
                $dveid = autoGerCode($devTypeData['abb']);
            }

            $oldGroup = $this->_model->getDataForWhere(array(
                'dveid' => $dveid
            ));
            if (!empty($oldGroup)) {
                $return = ['err' => 3, 'msg' => '资产编号已经存在'];
                return json($return);
            }

            $dvename = trim(input("request.dvename"));//auth
            $first_type = trim(input("request.first_type"));//auth
            $type = trim(input("request.type"));//auth
            $brand = trim(input("request.brand"));//auth
            $sn = trim(input("request.sn"));//auth
            $model = trim(input("request.model"));//auth
            $addr = trim(input("request.addr"));//auth
            $price = trim(input("request.price"));//auth
            $network = trim(input("request.network"));//auth
            $amount = trim(input("request.amount"));//auth
            $unit = trim(input("request.unit"));//auth
//             $rpwd =trim(input("request.rpwd"));//auth
            $mac = trim(input("request.mac"));//auth
            $ip = trim(input("request.ip"));//auth
            $insertData = array(
                'dveid' => $dveid,
                'dvename' => $dvename,
                'first_type' => $first_type,
                'type' => $type,
                'brand' => $brand,
                'sn' => $sn,
                'model' => $model,
                'addr' => $addr,
                'price' => $price,
                'network' => $network,
                'amount' => $amount,
                'unit' => $unit,
                'rpwd' => "",
                'mac' => $mac,
                'ip' => $ip,
                'stat' => 1,//0正常 1库存 2外借 3报废  4报修
                'stime' => date("Y-m-d H:i:s"),
                'ltime' => date("Y-m-d H:i:s"),
                'suid' => $this->LoginUserInfo['UserInfo']['id'],
                'uid' => $this->LoginUserInfo['UserInfo']['id'],
                'luid' => $this->LoginUserInfo['UserInfo']['id'],

            );
            $res = $this->_model->add($insertData);

            if ($res) {

                //记录档案变更日志
                $modelArchives = new \app\admin\model\Archives();
                $idata = array(
                    'devid' => $res,
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'dtime' => date("Y-m-d H:i:s"),
                    'info' => '入库',
                    'dep' => 0,
                    'first_dep' => 0,
                    'op_uid' => $this->LoginUserInfo['UserInfo']['id'],
                    'date' => date("Y-m"),
                    'ty' => 0,//类型 0入库，1领用 2归还 3报废
                );
                $flag = $modelArchives->add($idata);


                //操作日志记录
                $action = "资产编号[" . $insertData['dveid'] . "] 入库";

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 0,
                ]);

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $firstID = $FirstDepList[0]['id'];

        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $firstID
        ));//查询二级部门


        foreach ($SecondDepList as $k => $v) {
            $SecondDepList[$v['id']] = $v;
        }
        foreach ($FirstDepList as $k => $v) {
            $FirstDepList[$v['id']] = $v;
        }


        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $FirstDepList);


        //设置全局信息
        $title = "添加资产";
        $this->assign('title', $title);

        return view('addData');

    }


    public function addDataJob()
    {
        $time = time();
        $this->_model = new \app\admin\model\Job();

        $tcfgModel = new \app\admin\model\Tcfg();
        $tcfgLists = $tcfgModel->getDataForWheres();

        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {


            $conts = trim(input("request.conts"));//auth
            $bxtype = trim(input("request.bxtype"));//auth
            $s_type = trim(input("request.s_type"));//auth
            $s_val = trim(input("request.s_val"));//auth
            $phone = trim(input("request.phone"));//auth
            $office_no = trim(input("request.office_no"));//auth
            $tcfgTemp = trim(input("request.tcfg"));//auth
            $tcfg = '';
            $tcfg_id = '0';
            if (!empty($tcfgTemp)) {
                $tcfgTemp = explode("||", $tcfgTemp);
                $tcfg_id = $tcfgTemp[0];
                $tcfg = $tcfgTemp[1];
            }

            if ($bxtype == 1) {

                $insertData = array(
                    'id' => getJobVer(),
                    'devid' => 0,
                    'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                    'duser' => 0,
                    //'duser'=>$this->LoginUserInfo['UserInfo']['id'],
                    'log' => '',
                    'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                    'stime' => date("Y-m-d H:i:s"),
                    //                         'etime'=>date("Y-m-d H:i:s"),
                    'etime' => 0,
                    'conts' => $conts,
                    'type' => 1,
                    'phone' => $phone,
                    'office_no' => $office_no,
                    'tcfg' => $tcfg,
                    'tcfg_id' => $tcfg_id,
                    'job_type' => 0,
                    'ctime' => time(),
                );
            } else {
                $insertData = array(
                    'id' => getJobVer(),
                    'devid' => $s_val,
                    'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                    'duser' => 0,
                    'log' => '',
                    'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                    'stime' => date("Y-m-d H:i:s"),
                    'etime' => 0,
                    'conts' => $conts,
                    'type' => 0,
                    'phone' => $phone,
                    'office_no' => $office_no,
                    'tcfg' => $tcfg,
                    'tcfg_id' => $tcfg_id,
                    'job_type' => 0,
                    'ctime' => time(),
                );


            }
            $res = $this->_model->add($insertData);

            if ($res) {

                //操作日志记录
                $action = "硬件维修";
                if ($bxtype == 1) {
                    $action = "申请技术支持";
                }

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 0,
                ]);
                increaseAlert(1);
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //设置全局信息
        $title = "新增任务";
        $this->assign('title', $title);
        $this->assign('tcfgLists', $tcfgLists);

        return view('addDataJob');

    }


    public function addJobJcBX()
    {
        $time = time();
        $this->_model = new \app\admin\model\Job();

        $tcfgModel = new \app\admin\model\Tcfg();
        $tcfgLists = $tcfgModel->getDataForWheres();

        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {


            $conts = trim(input("request.conts"));//auth
            $bxtype = trim(input("request.bxtype"));//auth
            $s_type = trim(input("request.s_type"));//auth
            $s_val = trim(input("request.s_val"));//auth
            $phone = trim(input("request.phone"));//auth
            $office_no = trim(input("request.office_no"));//auth
            $tcfgTemp = trim(input("request.tcfg"));//auth
            $tcfg = '';
            $tcfg_id = '0';
            if (!empty($tcfgTemp)) {
                $tcfgTemp = explode("||", $tcfgTemp);
                $tcfg_id = $tcfgTemp[0];
                $tcfg = $tcfgTemp[1];
            }


            $insertData = array(
                'id' => getJobVer(),
                'devid' => 0,
                'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                'duser' => 0,
                //'duser'=>$this->LoginUserInfo['UserInfo']['id'],
                'log' => '',
                'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                'stime' => date("Y-m-d H:i:s"),
                //                         'etime'=>date("Y-m-d H:i:s"),
                'etime' => 0,
                'conts' => $conts,
                'type' => 1,
                'phone' => $phone,
                'office_no' => $office_no,
                'tcfg' => $tcfg,
                'tcfg_id' => $tcfg_id,
                'job_type' => 1,
                'op_type' => 3,
                'ctime' => time(),
            );

            $res = $this->_model->add($insertData);

            if ($res) {

                //操作日志记录
                $action = "硬件维修";
                if ($bxtype == 1) {
                    $action = "申请技术支持";
                }

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 0,
                ]);
                increaseAlert(2);
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //设置全局信息
        $title = "新增报修";
        $this->assign('title', $title);
        $this->assign('tcfgLists', $tcfgLists);

        return view('addJobJcBX');

    }

    public function addJcDataJob()
    {
        $time = time();
        $this->_model = new \app\admin\model\Job();

        $tcfgModel = new \app\admin\model\Tcfg();
        $tcfgLists = $tcfgModel->getDataForWheres($w = array('ty' => 1));

        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {

            $op_type = trim(input("request.op_type"));//auth
            if ($op_type == 1) {
//                 phone:phone,
//                 name:name,
//                 office_no:office_no,
//                 stime:stime,
//                 people_num:people_num,
//                 conts:conts,
//                 op_type:1,//1会议保障 2餐饮保障

                $phone = trim(input("request.phone"));//auth
                $name = trim(input("request.name"));//auth
                $office_no = trim(input("request.office_no"));//auth
                $stime = trim(input("request.stime"));//auth
                $people_num = trim(input("request.people_num"));//auth
                $conts = trim(input("request.conts"));//auth


                $insertData = array(
                    'id' => getJobVer(),
                    'devid' => 0,
                    'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                    'duser' => 0,
                    //'duser'=>$this->LoginUserInfo['UserInfo']['id'],
                    'log' => '',
                    'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                    'phone' => $phone,
                    'name' => $name,
                    'office_no' => $office_no,
                    'stime' => $stime,
                    'people_num' => $people_num,
                    'conts' => $conts,
                    'job_type' => 1,
                    'type' => 1,
                    'ctime' => $time,
                    'op_type' => 1,
                );
            } else {

                $phone = trim(input("request.phone"));//auth
                $stime = trim(input("request.stime"));//auth
                $people_num = trim(input("request.people_num"));//auth
                $conts = trim(input("request.conts"));//auth

                $insertData = array(
                    'id' => getJobVer(),
                    'devid' => 0,
                    'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                    'duser' => 0,
                    //'duser'=>$this->LoginUserInfo['UserInfo']['id'],
                    'log' => '',
                    'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                    'phone' => $phone,
                    'name' => '',
                    'office_no' => '',
                    'stime' => $stime,
                    'people_num' => $people_num,
                    'conts' => $conts,
                    'job_type' => 1,
                    'type' => 1,
                    'ctime' => $time,
                    'op_type' => 2,
                );
            }
            $res = $this->_model->add($insertData);

            if ($res) {

                //操作日志记录

                if ($op_type == 1) {
                    $action = "会议保障";
                } else {
                    $action = "餐饮保障";
                }

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 0,
                ]);
                increaseAlert(2);

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //设置全局信息
        $title = "业务申请";
        $this->assign('title', $title);
        $this->assign('tcfgLists', $tcfgLists);

        return view('addJcDataJob');

    }


    public function addJcDataJob1()
    {
        $time = time();
        $this->_model = new \app\admin\model\Job();

        $tcfgModel = new \app\admin\model\Tcfg();
        $tcfgLists = $tcfgModel->getDataForWheres($w = array('ty' => 1));

        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {

            $op_type = trim(input("request.op_type"));//auth
            if ($op_type == 1) {
                //                 phone:phone,
                //                 name:name,
                //                 office_no:office_no,
                //                 stime:stime,
                //                 people_num:people_num,
                //                 conts:conts,
                //                 op_type:1,//1会议保障 2餐饮保障

                $phone = trim(input("request.phone"));//auth
                $name = trim(input("request.name"));//auth
                $office_no = trim(input("request.office_no"));//auth
                $stime = trim(input("request.stime"));//auth
                $people_num = trim(input("request.people_num"));//auth
                $conts = trim(input("request.conts"));//auth


                $insertData = array(
                    'id' => getJobVer(),
                    'devid' => 0,
                    'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                    'duser' => 0,
                    //'duser'=>$this->LoginUserInfo['UserInfo']['id'],
                    'log' => '',
                    'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                    'phone' => $phone,
                    'name' => $name,
                    'office_no' => $office_no,
                    'stime' => $stime,
                    'people_num' => $people_num,
                    'conts' => $conts,
                    'job_type' => 1,
                    'type' => 1,
                    'ctime' => $time,
                    'op_type' => 1,
                );
            } else {

                $phone = trim(input("request.phone"));//auth
                $stime = trim(input("request.stime"));//auth
                $people_num = trim(input("request.people_num"));//auth
                $conts = trim(input("request.conts"));//auth

                $insertData = array(
                    'id' => getJobVer(),
                    'devid' => 0,
                    'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                    'duser' => 0,
                    //'duser'=>$this->LoginUserInfo['UserInfo']['id'],
                    'log' => '',
                    'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                    'phone' => $phone,
                    'name' => '',
                    'office_no' => '',
                    'stime' => $stime,
                    'people_num' => $people_num,
                    'conts' => $conts,
                    'job_type' => 1,
                    'type' => 1,
                    'ctime' => $time,
                    'op_type' => 2,
                );
            }
            $res = $this->_model->add($insertData);

            if ($res) {

                //操作日志记录

                if ($op_type == 1) {
                    $action = "会议保障";
                } else {
                    $action = "餐饮保障";
                }

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 0,
                ]);
                increaseAlert(2);

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //设置全局信息
        $title = "业务申请";
        $this->assign('title', $title);
        $this->assign('tcfgLists', $tcfgLists);

        return view('addJcDataJob1');

    }


    public function addFjDataJob()
    {
        $opTime = trim($_REQUEST['opTime']);
        $time = time();
        $this->_model = new \app\admin\model\Job();

        $tcfgModel = new \app\admin\model\Tcfg();
        $tcfgLists = $tcfgModel->getDataForWheres($w = array('ty' => 2, 'is_hidden' => 0));

        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {
            $phone = trim(input("request.phone"));//auth
            $stime = trim(input("request.stime"));//auth
            $people_num = trim(input("request.people_num"));//auth
            $conts = trim(input("request.conts"));//auth
            $name = trim(input("request.name"));//auth

            $tcfgTemp = trim(input("request.tcfg"));//auth
            $tcfg = '';
            $tcfg_id = '0';
            if (!empty($tcfgTemp)) {
                $tcfgTemp = explode("||", $tcfgTemp);
                $tcfg_id = $tcfgTemp[0];
                $tcfg = $tcfgTemp[1];
            }

            $insertData = array(
                'id' => getJobVer(),
                'devid' => 0,
                'tuser' => $this->LoginUserInfo['UserInfo']['id'],
                'duser' => 0,
                //'duser'=>$this->LoginUserInfo['UserInfo']['id'],
                'log' => '',
                'stat' => 0,//0已提交 1等待 2受理 3拒绝 4完结
                'phone' => $phone,
                'name' => $name,
                'office_no' => '',
                'stime' => $stime,
                'people_num' => $people_num,
                'conts' => $conts,
                'job_type' => 2,
                'type' => 1,
                'ctime' => $time,
                'op_type' => 0,
                'tcfg' => $tcfg,
                'tcfg_id' => $tcfg_id,
            );

            $res = $this->_model->add($insertData);

            if ($res) {

                //操作日志记录


                $action = "警力申请";

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 0,
                ]);
                increaseAlert(3);
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //设置全局信息
        $title = "业务申请";
        $this->assign('title', $title);
        $this->assign('opTime', $opTime);
        $this->assign('tcfgLists', $tcfgLists);

        return view('addFjDataJob');

    }


    public function editData()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {


            $dveid = trim(input("request.dveid"));//auth
            if (empty($dveid)) {
                $return = ['err' => 3, 'msg' => '对不起,该资产编号为空'];
                return json($return);
            }
            $oldGroup = $this->_model->getDataForWhere(array(
                'dveid' => $dveid
            ));

            if (!empty($oldGroup)) {
                if ($oldGroup['id'] != $id) {
                    $return = ['err' => 3, 'msg' => '对不起,该资产编号已经存在'];
                    return json($return);
                }

            }

            $dvename = trim(input("request.dvename"));//auth
            $first_type = trim(input("request.first_type"));//auth
            $type = trim(input("request.type"));//auth
            $brand = trim(input("request.brand"));//auth
            $sn = trim(input("request.sn"));//auth
            $model = trim(input("request.model"));//auth
            $addr = trim(input("request.addr"));//auth
            $price = trim(input("request.price"));//auth
            $network = trim(input("request.network"));//auth
            $amount = trim(input("request.amount"));//auth
            $unit = trim(input("request.unit"));//auth
//             $rpwd =trim(input("request.rpwd"));//auth
            $mac = trim(input("request.mac"));//auth
            $ip = trim(input("request.ip"));//auth
            if (empty($first_type)) {
                $first_type = 0;
            }
            if (empty($type)) {
                $type = 0;
            }


            $w = array(
                'id' => $id
            );
            $update = array(
                'dveid' => $dveid,
                'dvename' => $dvename,
                'first_type' => $first_type,
                'type' => $type,
                'brand' => $brand,
                'sn' => $sn,
                'model' => $model,
                'addr' => $addr,
                'price' => $price,
                'network' => $network,
                'amount' => $amount,
                'unit' => $unit,
//                 'rpwd'=>$rpwd,
                'mac' => $mac,
                'ip' => $ip,

            );
            $res = $this->_model->updateDataForWhere($update, $w);

            if ($res || ($res === 0)) {


                //操作日志记录
                $action = "资产编号[" . $update['dveid'] . "] 修改";

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 1,
                ]);

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        //查询用户
        $info = $this->_model->getDataForWhere(array('id' => $id));
        $this->assign('info', $info);
        //查询部门

        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $firstID = $FirstDepList[0]['id'];
        if ($info['first_type']) {
            $firstID = $info['first_type'];
        }
        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $firstID
        ));//查询二级部门


        foreach ($SecondDepList as $k => $v) {
            $SecondDepList[$v['id']] = $v;
        }
        foreach ($FirstDepList as $k => $v) {
            $FirstDepList[$v['id']] = $v;
        }


        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $FirstDepList);


        //设置全局信息
        $title = "编辑资产";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('editData');

    }


    public function baoxiu()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {
            $conts = trim(input("request.conts"));//auth
            $update = array('stat' => 4);

            $res = $this->_model->baoxiu($id, $conts, $this->LoginUserInfo['UserInfo']);

            if ($res || ($res === 0)) {
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        //资产信息
        $info = $this->_model->getDataForWhere(array('id' => $id));
        $this->assign('info', $info);
        //查询部门


        //查询目前之前有多少个报修正等待处理
        $jobModel = new \app\admin\model\Job();
        $jobData = $jobModel->getCount([
            'stat' => array("lt", 3)
        ]);

        //设置全局信息
        $title = "资产报修";
        $this->assign('title', $title);
        $this->assign('jobDataCount', $jobData);
        $this->assign('id', $id);
        return view('baoxiu');

    }


    public function depthlog()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth

        $starttime = trim(input("request.starttime"));//auth
        $endtime = trim(input("request.endtime"));//auth


        if (!empty($starttime) && !empty($endtime)) {
            $starttime = $starttime . " 00:00:00";
            $endtime = $endtime . " 23:59:59";
            $where['dtime'] = array('between', $starttime . "," . $endtime);
        }

        $where['devid'] = $id;

        $userModel = new \app\admin\model\User();
        //查询资产调配列表
        $archModel = new \app\admin\model\Archives();
        $lists = $archModel->lists($where, $this->pagesize);


        //查询用户信息

        if (!empty($lists['data'])) {

            $userList = array();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['rkUser'] = array();//操作人
                $lists['data'][$key]['useUser'] = array();//责任人
                if ($val['op_uid']) {
                    if ($userList[$val['op_uid']]) {
                        $lists['data'][$key]['rkUser'] = $userList[$val['op_uid']];
                    } else {
                        $tmpUserInfo = $userModel->getID($val['op_uid']);
                        if ($tmpUserInfo) {
                            $userList[$val['op_uid']] = $tmpUserInfo;
                            $lists['data'][$key]['rkUser'] = $tmpUserInfo;
                        }
                    }
                }


                if ($val['user']) {
                    if ($userList[$val['user']]) {
                        $lists['data'][$key]['useUser'] = $userList[$val['user']];
                    } else {
                        $tmpUserInfo = $userModel->getID($val['user']);
                        if ($tmpUserInfo) {
                            $userList[$val['user']] = $tmpUserInfo;
                            $lists['data'][$key]['useUser'] = $tmpUserInfo;
                        }
                    }
                }
            }
        }


        $this->assign('lists', $lists);
        //用户部门
        $depModel = new \app\admin\model\Dep();

        $DepList = $depModel->getAll();//查询一级部门

        $tempDepList = array();
        foreach ($DepList as $k => $v) {
            $tempDepList[$v['id']] = $v;
        }

        $this->assign('DepList', $tempDepList);


        //设置全局信息
        $title = "资产调配记录";
        $this->assign('title', $title);
        $this->assign('id', $id);
        $this->assign('request', input("request."));
        return view('depthlog');

    }


    public function baoxiulog()
    {


        $starttime = trim(input("request.starttime"));//auth
        $endtime = trim(input("request.endtime"));//auth
        $id = trim(input("request.id"));//auth
        $stat = trim(input("request.stat"));//auth

        if ($stat >= '0') {
            $where['stat'] = $stat;
        }

        if (!empty($starttime) && !empty($endtime)) {
            $starttime = $starttime . " 00:00:00";
            $endtime = $endtime . " 23:59:59";
            $where['stime'] = array('between', $starttime . "," . $endtime);
        }

        $where['devid'] = $id;

        $devlistModel = new \app\admin\model\Devlist();
        $tmpDevlistInfo = $devlistModel->getID($id);


        $jobModel = new \app\admin\model\Job();
        $lists = $jobModel->lists($where, $this->pagesize);
        if (!empty($lists['data'])) {

            $userList = array();

            $UserModel = new \app\admin\model\User();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['devlistInfo'] = $tmpDevlistInfo;
                $lists['data'][$key]['tuserInfo'] = array();
                $lists['data'][$key]['duserInfo'] = array();

                if ($val['tuser']) {
                    if ($userList[$val['tuser']]) {
                        $lists['data'][$key]['tuserInfo'] = $userList[$val['tuser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['tuser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['tuserInfo'] = $tempUserInfo;
                        }
                    }
                }
                if ($val['duser']) {
                    if ($userList[$val['duser']]) {
                        $lists['data'][$key]['duserInfo'] = $userList[$val['duser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['duser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['duserInfo'] = $tempUserInfo;
                        }
                    }
                }


            }
        }


        $this->assign('lists', $lists);


        //查询用户部门
        $depModel = new \app\admin\model\Dep();

        $tmpUserDepList = $depModel->getAll();//查询一级部门

        $userDepList = array();
        if ($tmpUserDepList) {
            foreach ($tmpUserDepList as $key => $val) {
                $userDepList[$val['id']] = $val;
            }
        }


        $this->assign('userDepList', $userDepList);
        $this->assign('id', $id);
        $this->assign('request', input("request."));
        return view('baoxiulog');

    }


    public function depthData()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        //查询资产信息
        $info = $this->_model->getDataForWhere(array('id' => $id));
        $this->assign('info', $info);
        if ($sys_opt) {

            $users = trim(input("request.users"));//auth
            $stat = trim(input("request.stat"));//auth
            if (empty($users)) {
                $return = ['err' => 1, 'msg' => '操作失败，请选择责任人'];
                return json($return);
            }
            $update = array(
                'uid' => $users,
                'ltime' => date("Y-m-d H:i:s"),
                'stat' => $stat,
            );
            $res = $this->_model->diaopei(
                $update,
                $id, $this->LoginUserInfo['UserInfo']);

            if ($res || ($res === 0)) {


                //操作日志记录
                $action = "资产编号[" . $info['dveid'] . "] 调配资产";

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 2,
                ]);

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //查询部门
        $depModel = new \app\admin\model\Dep();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $tmpFirstID = $FirstDepList[0]['id'];

        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $tmpFirstID
        ));//查询二级部门
        //         print_r($SecondDepList);
        $tmpSecondDepList = array();
        foreach ($SecondDepList as $k => $v) {
            $tmpSecondDepList[$v['id']] = $v;
        }
        $tmpFirstDepList = array();
        foreach ($FirstDepList as $k => $v) {
            $tmpFirstDepList[$v['id']] = $v;
        }


        $this->assign('SecondDepList', $tmpSecondDepList);
        $this->assign('FirstDepList', $tmpFirstDepList);

        //用户分组
        //查询分组
        $groupList = array();
        $groupModel = new \app\admin\model\Group();
        $groupList = $groupModel->getGroupList();
        $this->assign('groupList', $groupList);

        $groupList_mk = array();
        foreach ($groupList as $k => $v) {
            $groupList_mk[$v['id']] = $v;
        }

        $this->assign('groupList_mk', $groupList_mk);
        //查询用户

        //设置全局信息
        $title = "资产调配";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('depthData');

    }

    public function infoData()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {


            $dveid = trim(input("request.dveid"));//auth
            if (empty($dveid)) {
                $return = ['err' => 3, 'msg' => '对不起,该资产编号为空'];
                return json($return);
            }
            $oldGroup = $this->_model->getDataForWhere(array(
                'dveid' => $dveid
            ));

            if (!empty($oldGroup)) {
                if ($oldGroup['id'] != $id) {
                    $return = ['err' => 3, 'msg' => '对不起,该资产编号已经存在'];
                    return json($return);
                }

            }

            $dvename = trim(input("request.dvename"));//auth
            $first_type = trim(input("request.first_type"));//auth
            $type = trim(input("request.type"));//auth
            $brand = trim(input("request.brand"));//auth
            $sn = trim(input("request.sn"));//auth
            $model = trim(input("request.model"));//auth
            $addr = trim(input("request.addr"));//auth
            $price = trim(input("request.price"));//auth
            $network = trim(input("request.network"));//auth
            $amount = trim(input("request.amount"));//auth
            $unit = trim(input("request.unit"));//auth
            $rpwd = trim(input("request.rpwd"));//auth
            $mac = trim(input("request.mac"));//auth
            $ip = trim(input("request.ip"));//auth
            if (empty($first_type)) {
                $first_type = 0;
            }
            if (empty($type)) {
                $type = 0;
            }


            $w = array(
                'id' => $id
            );
            $update = array(
                'dveid' => $dveid,
                'dvename' => $dvename,
                'first_type' => $first_type,
                'type' => $type,
                'brand' => $brand,
                'sn' => $sn,
                'model' => $model,
                'addr' => $addr,
                'price' => $price,
                'network' => $network,
                'amount' => $amount,
                'unit' => $unit,
                'rpwd' => $rpwd,
                'mac' => $mac,
                'ip' => $ip,

            );
            $res = $this->_model->updateDataForWhere($update, $w);

            if ($res || ($res === 0)) {
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        //查询用户
        $info = $this->_model->getDataForWhere(array('id' => $id));


        //查询责任人start
        $userList = array();
        $userModel = new \app\admin\model\User();
        $info['rkUser'] = array();
        $info['useUser'] = array();
        if ($info['suid']) {
            if ($userList[$info['suid']]) {
                $info['rkUser'] = $userList[$info['suid']];
            } else {
                $tmpUserInfo = $userModel->getID($info['suid']);
                if ($tmpUserInfo) {
                    $userList[$info['suid']] = $tmpUserInfo;
                    $info['rkUser'] = $tmpUserInfo;
                }
            }
        }


        if ($info['uid']) {
            if ($userList[$info['uid']]) {
                $info['useUser'] = $userList[$info['uid']];
            } else {
                $tmpUserInfo = $userModel->getID($info['uid']);
                if ($tmpUserInfo) {
                    $userList[$info['uid']] = $tmpUserInfo;
                    $info['useUser'] = $tmpUserInfo;
                }
            }
        }

        //查询责任人end
        $this->assign('info', $info);

        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $firstID = $FirstDepList[0]['id'];
        if ($info['first_type']) {
            $firstID = $info['first_type'];
        }
        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $firstID
        ));//查询二级部门


        foreach ($SecondDepList as $k => $v) {
            $SecondDepList[$v['id']] = $v;
        }
        foreach ($FirstDepList as $k => $v) {
            $FirstDepList[$v['id']] = $v;
        }


        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $FirstDepList);


        //设置全局信息
        $title = "资产详情";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('infoData');

    }


    public function bminfoData()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {


            $dveid = trim(input("request.dveid"));//auth
            if (empty($dveid)) {
                $return = ['err' => 3, 'msg' => '对不起,该资产编号为空'];
                return json($return);
            }
            $oldGroup = $this->_model->getDataForWhere(array(
                'dveid' => $dveid
            ));

            if (!empty($oldGroup)) {
                if ($oldGroup['id'] != $id) {
                    $return = ['err' => 3, 'msg' => '对不起,该资产编号已经存在'];
                    return json($return);
                }

            }

            $dvename = trim(input("request.dvename"));//auth
            $first_type = trim(input("request.first_type"));//auth
            $type = trim(input("request.type"));//auth
            $brand = trim(input("request.brand"));//auth
            $sn = trim(input("request.sn"));//auth
            $model = trim(input("request.model"));//auth
            $addr = trim(input("request.addr"));//auth
            $price = trim(input("request.price"));//auth
            $network = trim(input("request.network"));//auth
            $amount = trim(input("request.amount"));//auth
            $unit = trim(input("request.unit"));//auth
            $rpwd = trim(input("request.rpwd"));//auth
            $mac = trim(input("request.mac"));//auth
            $ip = trim(input("request.ip"));//auth
            if (empty($first_type)) {
                $first_type = 0;
            }
            if (empty($type)) {
                $type = 0;
            }


            $w = array(
                'id' => $id
            );
            $update = array(
                'dveid' => $dveid,
                'dvename' => $dvename,
                'first_type' => $first_type,
                'type' => $type,
                'brand' => $brand,
                'sn' => $sn,
                'model' => $model,
                'addr' => $addr,
                'price' => $price,
                'network' => $network,
                'amount' => $amount,
                'unit' => $unit,
                'rpwd' => $rpwd,
                'mac' => $mac,
                'ip' => $ip,

            );
            $res = $this->_model->updateDataForWhere($update, $w);

            if ($res || ($res === 0)) {
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        //查询用户
        $info = $this->_model->getDataForWhere(array('id' => $id));


        //查询责任人start
        $userList = array();
        $userModel = new \app\admin\model\User();
        $info['rkUser'] = array();
        $info['useUser'] = array();
        if ($info['suid']) {
            if ($userList[$info['suid']]) {
                $info['rkUser'] = $userList[$info['suid']];
            } else {
                $tmpUserInfo = $userModel->getID($info['suid']);
                if ($tmpUserInfo) {
                    $userList[$info['suid']] = $tmpUserInfo;
                    $info['rkUser'] = $tmpUserInfo;
                }
            }
        }


        if ($info['uid']) {
            if ($userList[$info['uid']]) {
                $info['useUser'] = $userList[$info['uid']];
            } else {
                $tmpUserInfo = $userModel->getID($info['uid']);
                if ($tmpUserInfo) {
                    $userList[$info['uid']] = $tmpUserInfo;
                    $info['useUser'] = $tmpUserInfo;
                }
            }
        }


        //查询责任人end
        $this->assign('info', $info);

        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $firstID = $FirstDepList[0]['id'];
        if ($info['first_type']) {
            $firstID = $info['first_type'];
        }
        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $firstID
        ));//查询二级部门


        foreach ($SecondDepList as $k => $v) {
            $SecondDepList[$v['id']] = $v;
        }
        foreach ($FirstDepList as $k => $v) {
            $FirstDepList[$v['id']] = $v;
        }


        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $FirstDepList);


        //设置全局信息
        $title = "资产详情";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('bminfoData');

    }


    public function fjInfoData()
    {

        $id = trim(input("request.id"));//auth
        $modelJob = new \app\admin\model\Job();
        //查询工单信息
        $info = $modelJob->getDataForWhere(array('id' => $id));
        //查询资产信息
        $zcModel = new \app\admin\model\Devlist();
        $zcInfo = $zcModel->getDataForWhere(array('id' => $info['devid']));

        //查询责任人start
        $userList = array();
        $userModel = new \app\admin\model\User();
        $zcInfo['rkUser'] = array();
        $zcInfo['useUser'] = array();
        if ($zcInfo['suid']) {
            if ($userList[$zcInfo['suid']]) {
                $zcInfo['rkUser'] = $userList[$zcInfo['suid']];
            } else {
                $tmpUserInfo = $userModel->getID($zcInfo['suid']);
                if ($tmpUserInfo) {
                    $userList[$zcInfo['suid']] = $tmpUserInfo;
                    $zcInfo['rkUser'] = $tmpUserInfo;
                }
            }
        }


        if ($zcInfo['uid']) {
            if ($userList[$zcInfo['uid']]) {
                $zcInfo['useUser'] = $userList[$zcInfo['uid']];
            } else {
                $tmpUserInfo = $userModel->getID($zcInfo['uid']);
                if ($tmpUserInfo) {
                    $userList[$zcInfo['uid']] = $tmpUserInfo;
                    $zcInfo['useUser'] = $tmpUserInfo;
                }
            }
        }


        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getAll();//查询一级部门


        $tDepListTemp = array();
        foreach ($FirstDepList as $k => $v) {
            $tDepListTemp[$v['id']] = $v;
        }


        $this->assign('tDepListTemp', $tDepListTemp);
        $this->assign('zcInfo', $zcInfo);


        //报修人信息
        if ($info['tuser']) {
            $info['bxUser'] = array();
            $info['bxFirstDept'] = array();
            $info['bxSencodDept'] = array();
            if ($userList[$info['tuser']]) {
                $info['bxUser'] = $userList[$info['tuser']];
            } else {
                $tmpUserInfo = $userModel->getID($info['tuser']);
                if ($tmpUserInfo) {
                    $info['bxUser'] = $tmpUserInfo;
                }
            }


            if ($info['bxUser']) {
                //查询所属部门
                $depModel = new \app\admin\model\Dep();
                if ($info['bxUser']['first_depid'])//一级部门
                {
                    $depInfo = $depModel->getID($info['bxUser']['first_depid']);
                    $info['bxFirstDept'] = $depInfo;
                }
                if ($info['bxUser']['depid'])//二级部门
                {
                    $depInfo = $depModel->getID($info['bxUser']['depid']);
                    $info['bxSencodDept'] = $depInfo;
                }
            }

        }

        //查询责任人end
        $this->assign('info', $info);

        //查询该任务的法警人员列表

        $relationPoliceList = $this->getPoliceForTask($info['id']);
        $this->assign('relationPoliceList', $relationPoliceList);
        //设置全局信息
        $title = "详情";

        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('fjInfoData');

    }


    public function getPoliceForTask($taskId)
    {
        if (empty($taskId)) {
            return array();
        }

        $sql = 'select a.uid as uid,a.mid as mid,b.uname as uname,b.nickname as nickname,b.phone as phone,b.`group` as `group`,b.first_depid as first_depid,b.depid as depid,b.stat as stat from h_jobuser as a LEFT JOIN h_user as b on a.uid = b.id  where mid=' . $taskId;
        $policeList = \think\Db::query($sql);
        return $policeList;

    }

    public function jcInfoData()
    {

        $id = trim(input("request.id"));//auth
        $modelJob = new \app\admin\model\Job();
        //查询工单信息
        $info = $modelJob->getDataForWhere(array('id' => $id));
        //查询资产信息
        $zcModel = new \app\admin\model\Devlist();
        $zcInfo = $zcModel->getDataForWhere(array('id' => $info['devid']));

        //查询责任人start
        $userList = array();
        $userModel = new \app\admin\model\User();
        $zcInfo['rkUser'] = array();
        $zcInfo['useUser'] = array();
        if ($zcInfo['suid']) {
            if ($userList[$zcInfo['suid']]) {
                $zcInfo['rkUser'] = $userList[$zcInfo['suid']];
            } else {
                $tmpUserInfo = $userModel->getID($zcInfo['suid']);
                if ($tmpUserInfo) {
                    $userList[$zcInfo['suid']] = $tmpUserInfo;
                    $zcInfo['rkUser'] = $tmpUserInfo;
                }
            }
        }


        if ($zcInfo['uid']) {
            if ($userList[$zcInfo['uid']]) {
                $zcInfo['useUser'] = $userList[$zcInfo['uid']];
            } else {
                $tmpUserInfo = $userModel->getID($zcInfo['uid']);
                if ($tmpUserInfo) {
                    $userList[$zcInfo['uid']] = $tmpUserInfo;
                    $zcInfo['useUser'] = $tmpUserInfo;
                }
            }
        }


        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getAll();//查询一级部门


        $tDepListTemp = array();
        foreach ($FirstDepList as $k => $v) {
            $tDepListTemp[$v['id']] = $v;
        }


        $this->assign('tDepListTemp', $tDepListTemp);
        $this->assign('zcInfo', $zcInfo);


        //报修人信息
        if ($info['tuser']) {
            $info['bxUser'] = array();
            $info['bxFirstDept'] = array();
            $info['bxSencodDept'] = array();
            if ($userList[$info['tuser']]) {
                $info['bxUser'] = $userList[$info['tuser']];
            } else {
                $tmpUserInfo = $userModel->getID($info['tuser']);
                if ($tmpUserInfo) {
                    $info['bxUser'] = $tmpUserInfo;
                }
            }


            if ($info['bxUser']) {
                //查询所属部门
                $depModel = new \app\admin\model\Dep();
                if ($info['bxUser']['first_depid'])//一级部门
                {
                    $depInfo = $depModel->getID($info['bxUser']['first_depid']);
                    $info['bxFirstDept'] = $depInfo;
                }
                if ($info['bxUser']['depid'])//二级部门
                {
                    $depInfo = $depModel->getID($info['bxUser']['depid']);
                    $info['bxSencodDept'] = $depInfo;
                }
            }

        }

        //查询责任人end
        $this->assign('info', $info);
        //设置全局信息
        $title = "详情";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('jcInfoData');

    }


    public function bxinfoData()
    {

        $id = trim(input("request.id"));//auth
        $modelJob = new \app\admin\model\Job();
        //查询工单信息
        $info = $modelJob->getDataForWhere(array('id' => $id));
        //查询资产信息
        $zcModel = new \app\admin\model\Devlist();
        $zcInfo = $zcModel->getDataForWhere(array('id' => $info['devid']));

        //查询责任人start
        $userList = array();
        $userModel = new \app\admin\model\User();
        $zcInfo['rkUser'] = array();
        $zcInfo['useUser'] = array();
        if ($zcInfo['suid']) {
            if ($userList[$zcInfo['suid']]) {
                $zcInfo['rkUser'] = $userList[$zcInfo['suid']];
            } else {
                $tmpUserInfo = $userModel->getID($zcInfo['suid']);
                if ($tmpUserInfo) {
                    $userList[$zcInfo['suid']] = $tmpUserInfo;
                    $zcInfo['rkUser'] = $tmpUserInfo;
                }
            }
        }


        if ($zcInfo['uid']) {
            if ($userList[$zcInfo['uid']]) {
                $zcInfo['useUser'] = $userList[$zcInfo['uid']];
            } else {
                $tmpUserInfo = $userModel->getID($zcInfo['uid']);
                if ($tmpUserInfo) {
                    $userList[$zcInfo['uid']] = $tmpUserInfo;
                    $zcInfo['useUser'] = $tmpUserInfo;
                }
            }
        }


        //查询部门
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getAll();//查询一级部门


        $tDepListTemp = array();
        foreach ($FirstDepList as $k => $v) {
            $tDepListTemp[$v['id']] = $v;
        }


        $this->assign('tDepListTemp', $tDepListTemp);
        $this->assign('zcInfo', $zcInfo);


        //报修人信息
        if ($info['tuser']) {
            $info['bxUser'] = array();
            $info['bxFirstDept'] = array();
            $info['bxSencodDept'] = array();
            if ($userList[$info['tuser']]) {
                $info['bxUser'] = $userList[$info['tuser']];
            } else {
                $tmpUserInfo = $userModel->getID($info['tuser']);
                if ($tmpUserInfo) {
                    $info['bxUser'] = $tmpUserInfo;
                }
            }


            if ($info['bxUser']) {
                //查询所属部门
                $depModel = new \app\admin\model\Dep();
                if ($info['bxUser']['first_depid'])//一级部门
                {
                    $depInfo = $depModel->getID($info['bxUser']['first_depid']);
                    $info['bxFirstDept'] = $depInfo;
                }
                if ($info['bxUser']['depid'])//二级部门
                {
                    $depInfo = $depModel->getID($info['bxUser']['depid']);
                    $info['bxSencodDept'] = $depInfo;
                }
            }

        }

        //查询责任人end
        $this->assign('info', $info);
        //设置全局信息
        $title = "报修详情";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('bxinfoData');

    }

    public function bxlists()
    {

        $starttime = trim(input("request.starttime"));//auth
        $endtime = trim(input("request.endtime"));//auth
        $stat = trim(input("request.stat"));//auth


        if (!empty($starttime) && !empty($endtime)) {
            $starttime = $starttime . " 00:00:00";
            $endtime = $endtime . " 23:59:59";
            $where['stime'] = array('between', $starttime . "," . $endtime);
        }
        if ($stat >= '0') {
            $where['stat'] = $stat;
        }

        $where['tuser'] = $this->LoginUserInfo['UserInfo']['id'];
        $where['job_type'] = 0;//工单类型 0技术科 1计财科  2法警队
        $model = new \app\admin\model\Job();
        $lists = $model->lists($where, $this->pagesize);
        if (!empty($lists['data'])) {

            $userList = array();
            $devlistModel = new \app\admin\model\Devlist();
            $UserModel = new \app\admin\model\User();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['devlistInfo'] = array();
                $lists['data'][$key]['tuserInfo'] = array();
                $lists['data'][$key]['duserInfo'] = array();
                if ($val['type'] == '0') {
                    $tmpDevlistInfo = $devlistModel->getID($val['devid']);
                    if ($tmpDevlistInfo) {
                        $lists['data'][$key]['devlistInfo'] = $tmpDevlistInfo;
                    }
                }
                if ($val['tuser']) {
                    if ($userList[$val['tuser']]) {
                        $lists['data'][$key]['tuserInfo'] = $userList[$val['tuser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['tuser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['tuserInfo'] = $tempUserInfo;
                        }
                    }
                }
                if ($val['duser']) {
                    if ($userList[$val['duser']]) {
                        $lists['data'][$key]['duserInfo'] = $userList[$val['duser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['duser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['duserInfo'] = $tempUserInfo;
                        }
                    }
                }


            }
        }


        $this->assign('lists', $lists);


        //查询用户部门
        $depModel = new \app\admin\model\Dep();

        $tmpUserDepList = $depModel->getAll();//查询一级部门

        $userDepList = array();
        if ($tmpUserDepList) {
            foreach ($tmpUserDepList as $key => $val) {
                $userDepList[$val['id']] = $val;
            }
        }


        $this->assign('userDepList', $userDepList);
        $this->assign('request', input("request."));
        return view('bxlists');

    }


    public function fjMyApplyLists()
    {

        $starttime = trim(input("request.starttime"));//auth
        $endtime = trim(input("request.endtime"));//auth
        $stat = trim(input("request.stat"));//auth


        if (!empty($starttime) && !empty($endtime)) {
            $starttime = $starttime . " 00:00:00";
            $endtime = $endtime . " 23:59:59";
            $where['stime'] = array('between', $starttime . "," . $endtime);
        }
        if ($stat >= '0') {
            $where['stat'] = $stat;
        }

        $where['tuser'] = $this->LoginUserInfo['UserInfo']['id'];
        $where['job_type'] = 2;//工单类型 0技术科 1计财科  2法警队

        $model = new \app\admin\model\Job();
        $lists = $model->lists($where, $this->pagesize);
        // print_r($lists);
        if (!empty($lists['data'])) {

            $userList = array();
            $devlistModel = new \app\admin\model\Devlist();
            $UserModel = new \app\admin\model\User();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['devlistInfo'] = array();
                $lists['data'][$key]['tuserInfo'] = array();
                $lists['data'][$key]['duserInfo'] = array();
                if ($val['type'] == '0') {
                    $tmpDevlistInfo = $devlistModel->getID($val['devid']);
                    if ($tmpDevlistInfo) {
                        $lists['data'][$key]['devlistInfo'] = $tmpDevlistInfo;
                    }
                }
                if ($val['tuser']) {
                    if ($userList[$val['tuser']]) {
                        $lists['data'][$key]['tuserInfo'] = $userList[$val['tuser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['tuser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['tuserInfo'] = $tempUserInfo;
                        }
                    }
                }
                if ($val['duser']) {
                    if ($userList[$val['duser']]) {
                        $lists['data'][$key]['duserInfo'] = $userList[$val['duser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['duser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['duserInfo'] = $tempUserInfo;
                        }
                    }
                }


            }
        }


        $this->assign('lists', $lists);


        //查询用户部门
        $depModel = new \app\admin\model\Dep();

        $tmpUserDepList = $depModel->getAll();//查询一级部门

        $userDepList = array();
        if ($tmpUserDepList) {
            foreach ($tmpUserDepList as $key => $val) {
                $userDepList[$val['id']] = $val;
            }
        }


        $this->assign('userDepList', $userDepList);
        $this->assign('request', input("request."));
        return view('fjMyApplyLists');

    }


    public function jcApply()
    {

        $starttime = trim(input("request.starttime"));//auth
        $endtime = trim(input("request.endtime"));//auth
        $stat = trim(input("request.stat"));//auth


        if (!empty($starttime) && !empty($endtime)) {
            $starttime = $starttime . " 00:00:00";
            $endtime = $endtime . " 23:59:59";
            $where['stime'] = array('between', $starttime . "," . $endtime);
        }
        if ($stat >= '0') {
            $where['stat'] = $stat;
        }

        $op_type = trim(input("request.op_type"));//auth
        if (!empty($op_type)) {
            $where['op_type'] = $op_type;
        }

        $where['tuser'] = $this->LoginUserInfo['UserInfo']['id'];
        $where['job_type'] = 1;//工单类型 0技术科 1计财科  2法警队

        $model = new \app\admin\model\Job();
        $lists = $model->lists($where, $this->pagesize);
        if (!empty($lists['data'])) {

            $userList = array();
            $devlistModel = new \app\admin\model\Devlist();
            $UserModel = new \app\admin\model\User();
            foreach ($lists['data'] as $key => $val) {
                $lists['data'][$key]['devlistInfo'] = array();
                $lists['data'][$key]['tuserInfo'] = array();
                $lists['data'][$key]['duserInfo'] = array();
                if ($val['type'] == '0') {
                    $tmpDevlistInfo = $devlistModel->getID($val['devid']);
                    if ($tmpDevlistInfo) {
                        $lists['data'][$key]['devlistInfo'] = $tmpDevlistInfo;
                    }
                }
                if ($val['tuser']) {
                    if ($userList[$val['tuser']]) {
                        $lists['data'][$key]['tuserInfo'] = $userList[$val['tuser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['tuser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['tuserInfo'] = $tempUserInfo;
                        }
                    }
                }
                if ($val['duser']) {
                    if ($userList[$val['duser']]) {
                        $lists['data'][$key]['duserInfo'] = $userList[$val['duser']];
                    } else {
                        $tempUserInfo = $UserModel->getID($val['duser']);
                        if ($tempUserInfo) {
                            $userList[$tempUserInfo['id']] = $tempUserInfo;
                            $lists['data'][$key]['duserInfo'] = $tempUserInfo;
                        }
                    }
                }


            }
        }


        $this->assign('lists', $lists);


        //查询用户部门
        $depModel = new \app\admin\model\Dep();

        $tmpUserDepList = $depModel->getAll();//查询一级部门

        $userDepList = array();
        if ($tmpUserDepList) {
            foreach ($tmpUserDepList as $key => $val) {
                $userDepList[$val['id']] = $val;
            }
        }


        $this->assign('userDepList', $userDepList);
        $this->assign('request', input("request."));
        return view('jcApply');

    }


    public function tj()
    {

        $firstType = trim(input("request.firstType"));//auth
        $stat = trim(input("request.stat"));//auth
        $catgoryList = array();
        $category = array();
        //查询资产分类
        $depModel = new \app\admin\model\Devtype();

        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门

        $tmpFID = array();
        $FirstDepListTmps = array();
        foreach ($FirstDepList as $k => $v) {
            $FirstDepListTmps[$v['id']] = $v;
            $tmpFID[] = $v['id'];

        }

        $FirstDepList = $FirstDepListTmps;

        $this->assign('FirstDepList', $FirstDepList);

        $sql = "";

        if ($firstType)//统计二级分类资产
        {

            $sql = 'select cat,num,totle from ( select type as cat,count(*) as num,sum(price) as totle from h_devlist ';
            $SecondDepList = $depModel->getDataForWheres(array(
                'father' => $firstType
            ));//查询二级部门

            $catgoryList = $SecondDepList;

            if ($stat >= '0') {
                $sql = $sql . " where stat='" . $stat . "'";
            }
            $sql = $sql . " group by `type` ) as a ";


            $tmpID = array();
            foreach ($SecondDepList as $key => $val) {
                $tmpID[] = $val['id'];
                $category[] = $val['dname'];
            }


            if (empty($tmpID)) {
                $tmpID = array(0);
            }

            $sql = $sql . " where a.cat in (" . implode(",", $tmpID) . ") ";

        } else {
            $sql = 'select cat,num,totle from( select first_type as cat,count(*) as num,sum(price) as totle from h_devlist ';

            if ($stat >= '0') {
                $sql = $sql . " where stat='" . $stat . "'";
            }
            $sql = $sql . " group by first_type) as a";

            $catgoryList = $FirstDepList;
            foreach ($FirstDepList as $k => $v) {

                $category[] = $v['dname'];
            }
            $sql = $sql . " where a.cat in (" . implode(",", $tmpFID) . ") ";


        }


        $tjData = \think\Db::query($sql);
        $tjDataTmp = array();
        foreach ($tjData as $key => $val) {
            $tjDataTmp[$val['cat']] = $val;
        }


        $numArr = array();
        $priceArr = array();

        $catgoryListTmps = array();

        foreach ($catgoryList as $key => $val) {
            $stmp = array();
            $stmp['id'] = $val['id'];
            $stmp['dname'] = $val['dname'];
            if (!empty($tjDataTmp[$val['id']])) {
                $numArr[] = $tjDataTmp[$val['id']]['num'];
                $priceArr[] = $tjDataTmp[$val['id']]['totle'];
                $stmp['num'] = $tjDataTmp[$val['id']]['num'];
                $stmp['totle'] = $tjDataTmp[$val['id']]['totle'];
            } else {
                $numArr[] = 0;
                $priceArr[] = 0;
                $stmp['num'] = 0;
                $stmp['totle'] = 0;
            }

            $catgoryListTmps[] = $stmp;
        }

//         print_r($numArr);
//         print_r($priceArr);
//         print_r($category);
        $this->assign('catgoryListTmps', $catgoryListTmps);
        $this->assign('tjDataTmp', $tjDataTmp);
        $this->assign('numArr', $numArr);
        $this->assign('priceArr', $priceArr);
        $this->assign('category', $category);
        $this->assign('request', input("request."));
        //设置全局信息
        $title = "资产统计";
        $this->assign('title', $title);
        return view('tj');
    }

    public function _getMonth()
    {
        $time = time();
        $month = date("Y-m", $time);
        return array(
            date("Y-m", strtotime("-11 month", $time)),
            date("Y-m", strtotime("-10 month", $time)),
            date("Y-m", strtotime("-9 month", $time)),
            date("Y-m", strtotime("-8 month", $time)),
            date("Y-m", strtotime("-7 month", $time)),
            date("Y-m", strtotime("-6 month", $time)),
            date("Y-m", strtotime("-5 month", $time)),
            date("Y-m", strtotime("-4 month", $time)),
            date("Y-m", strtotime("-3 month", $time)),
            date("Y-m", strtotime("-2 month", $time)),
            date("Y-m", strtotime("-1 month", $time)),
            date("Y-m", $time)

        );
    }
    //查询一年的入库记录
//     类型 0入库，1领用 2归还 3报废
    public function _logs($ty = 0)
    {
        $sql = "select count(*) as num,date from h_archives where ty=" . $ty . " group by date";
        $tjData = \think\Db::query($sql);

        return $tjData;
    }


    public function bg()
    {

        $bg_title = $this->_getMonth();
        $this->assign('bg_title', $bg_title);
        //类型 0入库，1领用 2归还 3报废
        $tmprk0 = $this->_logs(0);
        $data0 = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        if ($tmprk0) {
            $tmp = array();
            foreach ($tmprk0 as $key => $val) {
                $tmp[$val['date']] = $val;
            }
            $tmprk0 = $tmp;
        }

        $tmprk1 = $this->_logs(1);
        $data1 = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        if ($tmprk1) {
            $tmp = array();
            foreach ($tmprk1 as $key => $val) {
                $tmp[$val['date']] = $val;
            }
            $tmprk1 = $tmp;
        }

        $tmprk2 = $this->_logs(2);
        $data2 = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        if ($tmprk2) {
            $tmp = array();
            foreach ($tmprk2 as $key => $val) {
                $tmp[$val['date']] = $val;
            }
            $tmprk2 = $tmp;
        }


        $tmprk3 = $this->_logs(2);
        $data3 = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        if ($tmprk3) {
            $tmp = array();
            foreach ($tmprk3 as $key => $val) {
                $tmp[$val['date']] = $val;
            }
            $tmprk3 = $tmp;
        }

        $zongData = array();
        foreach ($bg_title as $key => $val) {
            if ($tmprk0[$val]) {
                $data0[$key] = $tmprk0[$val]['num'];
            }
            if ($tmprk1[$val]) {
                $data1[$key] = $tmprk1[$val]['num'];
            }
            if ($tmprk2[$val]) {
                $data2[$key] = $tmprk2[$val]['num'];
            }
            if ($tmprk3[$val]) {
                $data3[$key] = $tmprk3[$val]['num'];
            }
            $tempData = array(
                'title' => $val,
                'n0' => $data0[$key],
                'n1' => $data1[$key],
                'n2' => $data2[$key],
                'n3' => $data3[$key],
            );
            $zongData[] = $tempData;
        }

        $datas = array(
            $data0,
            $data1,
            $data2,
            $data3,
        );
        $this->assign('datas', $datas);
        $this->assign('zongData', $zongData);
        //设置全局信息
        $title = "变更统计";

        $this->assign('title', $title);

        return view('bg');
    }

    public function fjMyApply()
    {
        $month = trim($_REQUEST['month']);
        $currDate = date("Y-m-d");
        if (empty($month)) {
            $month = date("Y-m");
        }

        if ($month < date("Y-m")) {
            $month = date("Y-m");
        }
        $lastMonth = date("Y-m", strtotime('-1months', strtotime($month . "-01 00:00:00")));

        $nextMonth = date("Y-m", strtotime('+1months', strtotime($month . "-01 00:00:00")));

        $list = generalCal($month, $currDate);

        $this->assign('list', $list);
        $this->assign('currDate', $currDate);
        $this->assign('lastMonth', $lastMonth);
        $this->assign('nextMonth', $nextMonth);

        //获取总的法警队数据
        $policeList = getPoliceList();
        $totlePoliceNum = count($policeList);
        $this->assign('totlePoliceNum', $totlePoliceNum);
        //获取一个月的 警力使用数据
        $policeMonthCount = getPoliceCountForTime($month);
        $this->assign('policeMonthCount', $policeMonthCount);
        //获取一段时间 每天的已分配警力end

        return view('fjMyApply');
    }


}